package com.hy.study.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import java.io.IOException;

/**
 * 自定义filter
 *
 * @author huyong
 * @date 2024 年 01 月 08 日 15:07: 32
 */
@WebFilter(urlPatterns = "/*", filterName = "myFilter", displayName = "myfilter")
@Slf4j
public class MyFilter extends HttpFilter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info("doFilter()");
        log.info("before filter");
        super.doFilter(request, response, chain);
        log.info("end filter");
    }

    @Override
    public void destroy() {
        super.destroy();
        log.info("filter 请求完毕销毁");
    }

    @Override
    public void init() throws ServletException {
        super.init();
        log.info("filter 初始化");
    }
}
